#ifndef GLOBAL_H
#define GLOBAL_H
#define MAXSIZE 2048

#include <map>
#include <string>
#include <fstream>
#include <sys/socket.h>
#include <string.h>
#include <set>
#include <vector>
#include <atomic>
#include <random>
#include <chrono>
#include <sstream>
#include <mutex>
#include "MysqlConnectionPool.h"
#include "RedisClient.h"
using namespace std;

enum STATUSCODE
{
    S_SUCCESS = 0,
    S_FAILED
};

//存储全局 用户信息
extern map<string,int> m_usersocket;
//模拟redis
extern map<string,string> m_redis;
//群聊组 用户登录后需要自动加入群聊，（ 每次循环发送时，判断用户是否在线)
extern map<string,set<string>> m_group;
// user => group
extern map<string,string> m_user_group;

extern MySQLConnectionPool mysqlconnectionpool;


#define SEND(soc,str) send(soc,str.c_str(),strlen(str.c_str()),0);

#define SUCCESS(soc,str_t){\
    string str = "code=0&msg=";\
    str += str_t;\
    SEND(soc,str);\
}

#define FAILED(soc,str_t){\
    string str = "code=1&msg=";\
    str += str_t;\
    SEND(soc,str);\
}




namespace GL
{
    //mysql 登录读数据
    string ReadByUsername(string username);
    //写用户
    bool WriteUsername(string username,string password);

    //处理消息
    void serverHandle(int soc,string msg);
    //URL参数解析
    string GetValueBuUrl(const string &param,string key);
    //URL参数串构造
    string GenUrlParamString(const map<string,string> &map_param);

    void Split(const string& str, char _type,vector<string> &vec_ret);
    //cookie
    string GenCookie();

    //gid
    extern atomic<uint64_t> atomic_gid;
    uint64_t GetGid();

    //login status
    pair<string,int> GetLoginStatus(int conn);
} 

#endif